package fei.yuzhi.com.loveflowers.utils;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.List;

import fei.yuzhi.com.loveflowers.bean.ClassifyAllBean;
import fei.yuzhi.com.loveflowers.bean.ClassifyItemBean;
import fei.yuzhi.com.loveflowers.bean.ProductBean;
import android.util.Log;

import com.alibaba.fastjson.JSON;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import fei.yuzhi.com.loveflowers.bean.firstpagefrgamentbean.AdvListBean;
import fei.yuzhi.com.loveflowers.bean.firstpagefrgamentbean.Home1Bean;
import fei.yuzhi.com.loveflowers.bean.firstpagefrgamentbean.Home3Bean;
import fei.yuzhi.com.loveflowers.bean.firstpagefrgamentbean.Home7Bean;

/**
 * Created by Administrator on 2016/10/7.
 */
public class JieXi {
    public static final String ADVLISTBEEN="advListBeen";
    public static final String HOME1BEANLIST="home1BeanList";
    public static final String HOME3BEEN="home3Been";
    public static final String HOME7BEEN="home7Been";
    public static List<ClassifyAllBean.DatasBean> getClassifyAllData(String json) {
        List<ClassifyAllBean.DatasBean> list = new ArrayList<>();
        ClassifyAllBean bean = JSON.parseObject(json, ClassifyAllBean.class);
        list = bean.getDatas();
        return list;
    }

    public static List<ClassifyItemBean.DatasBean.ClassListBean.ChildBean> getClassifyItemDara(String json) {
        List<ClassifyItemBean.DatasBean.ClassListBean.ChildBean> list = new ArrayList<>();
        ClassifyItemBean bean = JSON.parseObject(json, ClassifyItemBean.class);
        list = bean.getDatas().getClassList().getChild();
        return list;
    }

    public static List<ProductBean.DatasBean.GoodsListBean> getProductData(String json) {
        List<ProductBean.DatasBean.GoodsListBean> list = new ArrayList<>();
        ProductBean bean = JSON.parseObject(json, ProductBean.class);
        list = bean.getDatas().getGoodsList();
        return list;
    }
    public static Map<String,List<?>> jieXi(String json) {
        Map<String,List<?>> map=new HashMap<>();
        List<AdvListBean> advListBeen=new ArrayList<>();
        List<Home1Bean> home1BeanList=new ArrayList<>();
        List<Home3Bean> home3Been =new ArrayList<>();
        List<Home7Bean> home7Been =new ArrayList<>();


        try {
            JSONObject object1=new JSONObject(json);
            JSONArray array1=object1.getJSONArray("datas");
            for (int i=0;i<array1.length();i++){
                JSONObject object2=array1.getJSONObject(i);
                Iterator<String> keys= array1.getJSONObject(i).keys();
                String key= keys.next();
                // Log.i("tag","++++>"+key);
                if ("adv_list".equals(key)){
                    JSONObject object3=object2.getJSONObject("adv_list");
                    String data=object3.getString("item");
                    advListBeen.addAll(JSON.parseArray(data, AdvListBean.class));

                }
                if ("home1".equals(key)){
                    String home1 = object2.getString("home1");
                    Home1Bean home1Bean = JSON.parseObject(home1, Home1Bean.class);
                    home1BeanList.add(home1Bean);
                }
                if ("home3".equals(key)){
                    JSONObject object3=object2.getJSONObject("home3");
                    String data=object3.getString("item");
                    home3Been.addAll(JSON.parseArray(data, Home3Bean.class));

                }
                if ("home7".equals(key)){
                    JSONObject object3=object2.getJSONObject("home7");
                    String data=object3.getString("item");
                    home7Been.addAll(JSON.parseArray(data, Home7Bean.class));

                }


            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        map.put(ADVLISTBEEN,advListBeen);
        map.put(HOME1BEANLIST,home1BeanList);
        map.put(HOME3BEEN,home3Been);
        map.put(HOME7BEEN,home7Been);

//        Log.i("tag","++advListBeen++>"+ advListBeen.size());
//        Log.i("tag","++home1Been++>"+home1BeanList.size());
//        Log.i("tag","++home3Been++>"+home3Been.size());
//        Log.i("tag","++home7Been++>"+home7Been.size());
        return map;
    }
}




